#! /bin/bash

CheckUrl() {
  timeout=5
  fails=0
  success=0

  # check a url can be connected

  while true
  do
    wget --timeout=${timeout} --tries=1 https://www.bilibili.com/ -q -O /dev/null
    
    if [ $? -gt 0 ]
    then
      fails+=1
    else
      success+=1
    fi

    if [ ${success} -ge 1 ]
    then
      echo "connection is good"
      break
    fi

    if [ ${fails} -ge 2  ]
    then
      echo "connection is bad"
      break
    fi

  done
}

CheckUrl
